﻿Public Class frmQuanLyTaiKhoan
    Dim da As DataProvider
    Public Sub LoadDS()
        da = New DataProvider
        Dim sql = "select * from TAIKHOAN"
        dgvDSTK.DataSource = da.ShowData(sql)
        
    End Sub
    Public Sub LoadLoaiTK()
        da = New DataProvider
        Dim Sql = "select distinct(TypeAccount) from TAIKHOAN"
        cbxTypeAccount.DataSource = da.ShowData(Sql)
        cbxTypeAccount.DisplayMember = "TypeAccount"
        'Dim dt As DataTable = da.ShowData(Sql)
        'Dim cmd As New SqlClient.SqlCommand(Sql, da.con)
    End Sub

    Private Sub frmQuanLyTaiKhoan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDS()
        LoadLoaiTK()
    End Sub

    Private Sub btnDong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub

    Private Sub dgvDSTK_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvDSTK.SelectionChanged
        Dim index = dgvDSTK.CurrentRow.Index
        Dim row = dgvDSTK.Rows.Item(index)
        txtID.Text = row.Cells(0).Value.ToString()
        txtUserName.Text = row.Cells(1).Value.ToString()
        txtPassWord.Text = row.Cells(2).Value.ToString()
        cbxTypeAccount.Text = row.Cells(3).Value.ToString()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim sql = "insert into TAIKHOAN(UserName,PassWord,TypeAccount) values('" + txtUserName.Text + "','" + txtPassWord.Text + "','" + cbxTypeAccount.Text + "')"
        da = New DataProvider
        da.SqlExcuteNonQuery(sql)
        LoadDS()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim sql = "delete from TAIKHOAN where ID = '" + txtID.Text + "'"
        da = New DataProvider
        da.SqlExcuteNonQuery(sql)
        LoadDS()
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim sql = "update TAIKHOAN " + _
                  "set UserName = '" + txtUserName.Text + "', PassWord = '" + txtPassWord.Text + "', TypeAccount = '" + cbxTypeAccount.Text + "' " + _
                  "where ID = '" + txtID.Text + "'"
        da = New DataProvider
        da.SqlExcuteNonQuery(sql)
        LoadDS()
    End Sub
End Class